home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_079 / sharedlib / interface.asm < prev    next >
Assembly Source File  |  1992-05-06  |  4KB  |  134 lines

  1. ;; Interface.ASM
  2. ;;        Copyright 1986, James M Synge
  3. ;;
  4. ;; This file contains the assembly language interfaces which
  5. ;; allow the C routines to be called from any language which
  6. ;; can push arguments on to the stack.
  7.  
  8.     far    code
  9.     far    data
  10.  
  11. ;; Imported Functions:
  12.  
  13.     public    _Library_Open
  14.     public    _Library_Close
  15.     public    _Library_Expunge
  16.  
  17.     public    _CreateTask
  18.     public    _DeleteTask
  19.  
  20. ;; Exported Functions:
  21.  
  22.     public    __Library_Open
  23.     public    __Library_Close
  24.     public    __Library_Expunge
  25.  
  26.     public    __CreateTask
  27.     public    __DeleteTask
  28.  
  29. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  30. ;;
  31. ;; Due to the fact that the Aztec C68K compiler does not use
  32. ;; the same register allocation as the rest of the system,
  33. ;; it tromps on some of the registers which it is supposed
  34. ;; to preserve.  It is designed to be the top level, making
  35. ;; calls to the rest of the system and NOT being called by
  36. ;; the OS.
  37. ;;
  38. ;; Using version 3.4a of the compiler, I find it necessary
  39. ;; to save A6.  Version 3.2a also stepped on D2 and D3.  I
  40. ;; have not yet seen any use of register A4, even though I'm
  41. ;; using the +R option on the CC command line.  Nonetheless,
  42. ;; I'll be cautious, and save A4.
  43. ;;
  44. ;; So?  So I've written an interlude for each of the
  45. ;; routines which the OS will be calling.  These interludes
  46. ;; know where the arguments are in the registers, and push
  47. ;; them onto the stack where they are useful.
  48. ;;
  49. ;; And after these interludes are the library specific
  50. ;; interlude routines.  These are designed to have their
  51. ;; arguments on the stack, as if called by a C routine.
  52.  
  53. AztecBugList:    reg    a4/a6
  54. AztecBugSize:    equ    2    ; 2 registers
  55.  
  56. ; AztecBugList_3_2a:    reg    d2/d3/a4/a6
  57.  
  58. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  59. ;;
  60. ;; These are the interlude routines for Library_Open,
  61. ;; Library_Close and Library_Expunge.  They enable these C
  62. ;; routines to receive the arguments which are in registers.
  63.  
  64. __Library_Open:
  65.     movem.l    AztecBugList,-(sp)
  66.     move.l    d0,-(sp)        ; Push the version
  67.     move.l    a6,-(sp)        ; and the lib base
  68.     jsr    _Library_Open
  69.     addq.l    #8,sp            ; Pop them
  70.     movem.l    (sp)+,AztecBugList
  71.     rts
  72.  
  73. __Library_Close:
  74.     movem.l    AztecBugList,-(sp)
  75.     move.l    a6,-(sp)        ; Push lib base
  76.     jsr    _Library_Close
  77.     addq.l    #4,sp            ; Pop it
  78.     movem.l    (sp)+,AztecBugList
  79.     rts
  80.  
  81. __Library_Expunge:
  82.     movem.l    AztecBugList,-(sp)
  83.     move.l    a6,-(sp)        ; Push lib base
  84.     jsr    _Library_Expunge
  85.     addq.l    #4,sp            ; Pop it
  86.     movem.l    (sp)+,AztecBugList
  87.     rts
  88.  
  89. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  90. ;;
  91. ;; Library specific interface routines.  These first push
  92. ;; certain registers to the stack to protect them, then push
  93. ;; the arguments from earlier on the stack.  The only reason
  94. ;; this is done is so that we can protect two of the
  95. ;; registers.  Otherwise the need for these silly routines
  96. ;; would totally disappear.
  97. ;;
  98. ;; In order to make it easy for those not familiar with
  99. ;; 68000 assembly language to add their own routines to a
  100. ;; library, and the corresponding interface routines, I've
  101. ;; written a macro which can be invoked to generate all the
  102. ;; code to protect the registers and move the arguments.
  103. ;; The macro, protect, is defined in the file Protect.i, but
  104. ;; I don't recommend reading it until after you get a good
  105. ;; feeling for the way macro's and assembly work.
  106. ;;
  107. ;; It is very easy to use protect.  The syntax should be:
  108. ;;
  109. ;;    label    PROTECT.L    address,n
  110. ;;
  111. ;; where label is the name of the routine you are creating,
  112. ;; for example __CreateTask below; address is the name of a
  113. ;; C routine (with the underscore prepended), just like
  114. ;; _CreateTask below; and finally n is the number of
  115. ;; longword arguments the routine takes.  No support is
  116. ;; supplied for variable numbers of arguments.  Nor support
  117. ;; for arguments which are not longwords.
  118.  
  119.     include protect.i
  120.  
  121. ; CreateTask(Task_Name, Startup_Routine, Cleanup_Routine,
  122. ;         Priority, Stack_Size)
  123.  
  124. __CreateTask    protect.l    _CreateTask,5
  125.  
  126. ; DeleteTask( Child )
  127.  
  128. __DeleteTask:    protect.l    _DeleteTask,1
  129.  
  130. ; Now that was pretty painless, wasn't it.  Macros are great
  131.  
  132.     ds.w    0
  133.         END
  134.